{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=61
  Verdict: Accepted
}
uses 
	SysUtils, Math;
 
var  	
	kk,p,cc,l,r:longint;
	a:array[-1000010..1000010] of longint;
	s,t:string;
	f:boolean;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
readln(s);
s:=trim(s);
cc:=0;
l:=0;
r:=-1;
f:=true;
while s<>'exit' do begin
	kk:=pos(' ',s);
	if kk=0 then t:=s else begin
		t:=copy(s,1,kk-1);
		delete(s,1,kk);
		p:=strtoint(s);
	end;
	if t='push_front' then begin
		if f then begin
			l:=0;
			r:=0;
			f:=false;
		end else dec(l);
		a[l]:=p;
		inc(cc);
		writeln('ok');		
	end else
	if t='push_back' then begin
		inc(r);
		inc(cc);
		a[r]:=p;
		f:=false;
		writeln('ok');
	end else
	if t='pop_front' then begin
		if cc=0 then writeln('error') else begin 
			writeln(a[l]);
			inc(l);
			dec(cc);
		end;
	end else 
	if t='pop_back' then begin
		if cc=0 then writeln('error') else begin 
			writeln(a[r]);
			dec(r);
			dec(cc);
		end;
	end else
	if t='front' then begin
		if cc=0 then writeln('error') else writeln(a[l]);
	end else 
	if t='back' then begin
		if cc=0 then writeln('error') else writeln(a[r]);
	end else 
	if t='size' then begin
		writeln(cc);
	end else
	if t='clear' then begin
		l:=0;
		r:=-1;
		cc:=0;
		f:=true;
		writeln('ok');
	end;
	readln(s);
	s:=trim(s);
end;
write('bye');
end.